package com.test.fundible.fundible_10_vip;

import static com.test.fundible.fundible_00_utils.FundibleUtil.startLoading;
import static com.test.fundible.fundible_00_utils.FundibleUtil.stopLoading;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.test.fundible.R;
import com.test.fundible.fundible_00_customer_service.Customer_fundibleServiceDialog;
import com.test.fundible.fundible_00_http.OkHttpUtil;


public class VipInfoActivity_fundible extends AppCompatActivity {

    private View vipBgView;
    private TextView expValueTv;
    private TextView upgradeDescTv;
    private View vipTopBgView;
    private ImageView vipIv;
    private TextView vTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fundible_vip_info);
        //tag2024
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

        vipBgView = findViewById(R.id.afvi_view_vipbg);
        expValueTv = findViewById(R.id.afvi_tv_exp_value);
        upgradeDescTv = findViewById(R.id.afvi_tv_upgrade_desc);
        vipTopBgView = findViewById(R.id.afvi_view_vip_top_bg);
        vipIv = findViewById(R.id.afvi_iv_vip);
        vTv = findViewById(R.id.afvi_tv_v);

        init();

    }

    private void init(){

        findViewById(R.id.afvi_ib_back).setOnClickListener(v -> onBackPressed());
        findViewById(R.id.afvi_ib_cs).setOnClickListener(v -> new Customer_fundibleServiceDialog(this).show());

        //下拉刷新
        SwipeRefreshLayout refreshLayout = findViewById(R.id.afvi_refreshlayout);
        refreshLayout.setOnRefreshListener(() -> {
            OkHttpUtil.getInstance_fundible().uploadEventPoint("VIP","REFRESH_PULL","");
            refreshLayout.setRefreshing(false);
            startLoading(this,"");
            OkHttpUtil.getInstance_fundible().requestUsPrcs(() -> OkHttpUtil.getInstance_fundible().requestUserInfo(this::refreshVipGrade));
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        startLoading(this,"");
        OkHttpUtil.getInstance_fundible().uploadEventPoint("VIP","START","");
        OkHttpUtil.getInstance_fundible().requestUsPrcs(() -> OkHttpUtil.getInstance_fundible().requestUserInfo(this::refreshVipGrade));
    }

    @Override
    protected void onPause() {
        super.onPause();
        OkHttpUtil.getInstance_fundible().uploadEventPoint("VIP","END","");
    }

    //刷新VIP数据
    @SuppressLint("SetTextI18n")
    private void refreshVipGrade(){

        stopLoading();

        int grade = Pers_fundibleonalIn_fundiblefo.getInstance().getGrade();
        int toNextExp = Pers_fundibleonalIn_fundiblefo.getInstance().getNextGradeExp();

        switch (grade){
            case 3:
                vipTopBgView.setBackgroundResource(R.drawable.bg_vip_top_v3);
                vipBgView.setBackgroundResource(R.drawable.bg_vip_3);
                vipIv.setBackgroundResource(R.drawable.img_vip_3);
                vTv.setText("V3");
                upgradeDescTv.setText(getString(R.string.pc_upgrade_desc_max));
                break;
            case 2:
                vipTopBgView.setBackgroundResource(R.drawable.bg_vip_top_v2);
                vipBgView.setBackgroundResource(R.drawable.bg_vip_2);
                vipIv.setBackgroundResource(R.drawable.img_vip_2);
                vTv.setText("V2");
                upgradeDescTv.setText(getString(R.string.pc_upgrade_desc,String.valueOf(toNextExp),"3"));
                break;
            default:
                vipTopBgView.setBackgroundResource(R.drawable.bg_vip_top_v1);
                vipBgView.setBackgroundResource(R.drawable.bg_vip_1);
                vipIv.setBackgroundResource(R.drawable.img_vip_1);
                vTv.setText("V1");
                upgradeDescTv.setText(getString(R.string.pc_upgrade_desc,String.valueOf(toNextExp),"2"));

        }

        expValueTv.setText(String.valueOf(Pers_fundibleonalIn_fundiblefo.getInstance().getExpValue()));

    }

}